using Microsoft.Practices.SmartClient.DisconnectedAgent;
using Metro.Admin.BusinessEntities;
using System;
using System.Collections.Generic;

namespace Metro.SmartClient.Infrastructure.Interface.DSA.SharedServiceClient
{
    // Generated code for the web service.
    // Use this proxy to make requests to the service when working in an application that is occasionally connected
    public partial class Agent
    {
        IRequestQueue requestQueue;

        public Agent(IRequestQueue requestQueue)
        {
            this.requestQueue = requestQueue;
        }

        #region UsersAuthentication

        /// <summary>
        /// Enqueues a request to the <c>UsersAuthentication</c> web service method through the agent.
        /// </summary>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid UsersAuthentication(String login, String password)
        {
            return UsersAuthentication(login, password, GetUsersAuthenticationDefaultBehavior());
        }

        /// <summary>
        /// Enqueues a request to the <c>UsersAuthentication</c> web service method through the agent.
        /// </summary>
        /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid UsersAuthentication(String login, String password, OfflineBehavior behavior)
        {
            behavior.ReturnCallback = new CommandCallback(typeof(Callback), "OnUsersAuthenticationReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnUsersAuthenticationException");

            return EnqueueRequest("UsersAuthentication", behavior, login, password);
        }

        public static OfflineBehavior GetUsersAuthenticationDefaultBehavior()
        {
            OfflineBehavior behavior = GetAgentDefaultBehavior();
            behavior.ReturnCallback = new CommandCallback(typeof(Callback), "OnUsersAuthenticationReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnUsersAuthenticationException");

            return behavior;
        }

        #endregion UsersAuthentication

        #region GetCompanyParameters

        /// <summary>
        /// Enqueues a request to the <c>GetCompanyParameters</c> web service method through the agent.
        /// </summary>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid GetCompanyParameters()
        {
            return GetCompanyParameters(GetGetCompanyParametersDefaultBehavior());
        }

        /// <summary>
        /// Enqueues a request to the <c>GetCompanyParameters</c> web service method through the agent.
        /// </summary>
        /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid GetCompanyParameters(OfflineBehavior behavior)
        {
            behavior.ReturnCallback = new CommandCallback(typeof(Callback), "OnGetCompanyParametersReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetCompanyParametersException");

            return EnqueueRequest("GetCompanyParameters", behavior);
        }

        public static OfflineBehavior GetGetCompanyParametersDefaultBehavior()
        {
            OfflineBehavior behavior = GetAgentDefaultBehavior();
            behavior.ReturnCallback = new CommandCallback(typeof(Callback), "OnGetCompanyParametersReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetCompanyParametersException");

            return behavior;
        }

        #endregion GetCompanyParameters

        #region GetOrdersFromUser

        /// <summary>
        /// Enqueues a request to the <c>GetOrdersFromUser</c> web service method through the agent.
        /// </summary>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid GetOrdersFromUser(String idUser, DateTime date, String market)
        {
            return GetOrdersFromUser(idUser, date, market, GetGetOrdersFromUserDefaultBehavior());
        }

        /// <summary>
        /// Enqueues a request to the <c>GetOrdersFromUser</c> web service method through the agent.
        /// </summary>
        /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid GetOrdersFromUser(String idUser, DateTime date, String market, OfflineBehavior behavior)
        {
            behavior.ReturnCallback = new CommandCallback(typeof(Callback), "OnGetOrdersFromUserReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetOrdersFromUserException");

            return EnqueueRequest("GetOrdersFromUser", behavior, idUser, date, market);
        }

        public static OfflineBehavior GetGetOrdersFromUserDefaultBehavior()
        {
            OfflineBehavior behavior = GetAgentDefaultBehavior();
            behavior.ReturnCallback = new CommandCallback(typeof(Callback), "OnGetOrdersFromUserReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetOrdersFromUserException");

            return behavior;
        }

        #endregion GetOrdersFromUser

        #region GetTransactionsFromUser

        /// <summary>
        /// Enqueues a request to the <c>GetTransactionsFromUser</c> web service method through the agent.
        /// </summary>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid GetTransactionsFromUser(String idUser, DateTime date, String market)
        {
            return GetTransactionsFromUser(idUser, date, market, GetGetTransactionsFromUserDefaultBehavior());
        }

        /// <summary>
        /// Enqueues a request to the <c>GetTransactionsFromUser</c> web service method through the agent.
        /// </summary>
        /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid GetTransactionsFromUser(String idUser, DateTime date, String market, OfflineBehavior behavior)
        {
            behavior.ReturnCallback = new CommandCallback(typeof(Callback), "OnGetTransactionsFromUserReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetTransactionsFromUserException");

            return EnqueueRequest("GetTransactionsFromUser", behavior, idUser, date, market);
        }

        public static OfflineBehavior GetGetTransactionsFromUserDefaultBehavior()
        {
            OfflineBehavior behavior = GetAgentDefaultBehavior();
            behavior.ReturnCallback = new CommandCallback(typeof(Callback), "OnGetTransactionsFromUserReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetTransactionsFromUserException");

            return behavior;
        }

        #endregion GetTransactionsFromUser

        #region Common

        public static OfflineBehavior GetAgentDefaultBehavior()
        {
            OfflineBehavior behavior = new OfflineBehavior();
            behavior.MaxRetries = 3;
            behavior.Stamps = 1;
            behavior.Expiration = DateTime.Now + new TimeSpan(1, 0, 0, 0);
            behavior.ProxyFactoryType = typeof(Microsoft.Practices.SmartClient.DisconnectedAgent.WCFProxyFactory<Metro.SmartClient.Infrastructure.Interface.SharedService.ISharedService>);

            return behavior;
        }

        private Guid EnqueueRequest(string methodName, OfflineBehavior behavior, params object[] arguments)
        {
            Request request = CreateRequest(methodName, behavior, arguments);

            requestQueue.Enqueue(request);

            return request.RequestId;
        }

        private static Request CreateRequest(string methodName, OfflineBehavior behavior, params object[] arguments)
        {
            Request request = new Request();
            request.MethodName = methodName;
            request.Behavior = behavior;
            request.CallParameters = arguments;

            request.OnlineProxyType = OnlineProxyType;
            request.Endpoint = Endpoint;

            return request;
        }

        public static Type OnlineProxyType
        {
            get
            {
                return typeof(Metro.SmartClient.Infrastructure.Interface.SharedService.SharedServiceClient);
            }
        }

        public static string Endpoint
        {
            get
            {
                return String.Empty;
            }
        }
        #endregion
    }
}
